using UnityEngine;

namespace PhysSound
{
	public class PhysSoundTempAudio : MonoBehaviour
	{
		private AudioSource audioSource;

		public void Initialize(PhysSoundTempAudioPool pool)
		{
			audioSource = base.gameObject.AddComponent<AudioSource>();
			base.transform.SetParent(pool.transform);
			base.gameObject.SetActive(value: false);
		}

		public void PlayClip(AudioClip clip, Vector3 point, AudioSource template, float volume, float pitch)
		{
			PhysSoundTempAudioPool.GetAudioSourceCopy(template, audioSource);
			base.transform.position = point;
			audioSource.clip = clip;
			audioSource.volume = volume;
			audioSource.pitch = pitch;
			base.gameObject.SetActive(value: true);
			audioSource.Play();
		}

		private void Update()
		{
			if (!audioSource.isPlaying)
			{
				base.transform.position = Vector3.zero;
				base.gameObject.SetActive(value: false);
			}
		}
	}
}
